package com.recommend.service.admin.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.recommend.domain.UserDomain;
import com.recommend.persistence.UserDomainMapper;
import com.recommend.service.UserService;

/**
 * Created by lw.
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    private final static Logger logger = org.slf4j.LoggerFactory.getLogger(LoginServiceImpl.class);

    @Resource
    private UserDomainMapper userDomainMapper;

    @Override
    public List<UserDomain> getAllUser(){
        return userDomainMapper.selectAll();
    }

    @Override
    public List<UserDomain> searchUser(UserDomain userDomain){
        List<UserDomain> list = userDomainMapper.selectListSelective(userDomain);
        logger.info("============================search:count={}=============", list.size());
        return list;
    }

    @Override
    public int searchUserByAccount(String account){
        UserDomain userDomain1 = new UserDomain();
        userDomain1.setAccount(account);
        UserDomain userDomain = userDomainMapper.selectSelective(userDomain1);
        if(userDomain != null){
            return 1;
        }else{
            return 0;
        }
    }

    @Override
    public UserDomain getUser(int userId){
        return userDomainMapper.selectByPrimaryKey(userId);
    }

    @Override
    public int updateUser(UserDomain userDomain){
        return userDomainMapper.updateByPrimaryKeySelective(userDomain);
    }

    @Override
    public int addUser(UserDomain userDomain){
        return userDomainMapper.insertSelective(userDomain);
    }
}
